package com.wst.system.config.xss;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
@WebFilter(filterName="XSSFilter", urlPatterns="/*" )
public class XSSFilter implements Filter {
 
    FilterConfig filterConfig = null;
 
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //System.out.println("过滤器初始化");
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse res = (HttpServletResponse) servletResponse;

        StringBuffer fileURL = req.getRequestURL();

        if (fileURL.indexOf("/api/article/contentFileMng") == -1) {
        	//该问题会导致将前端的一些特殊字符进行
            //filterChain.doFilter(new XssHttpServletRequestWrapper((HttpServletRequest) servletRequest), servletResponse);
        	filterChain.doFilter(servletRequest, servletResponse);
        }else {
            filterChain.doFilter(servletRequest, servletResponse);
        }

    }
 
    @Override
    public void destroy() {
        //System.out.println("过滤器销毁");
        this.filterConfig = null;
    }
 
}
